package com.example.demo.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.querydsl.QPageRequest;
import org.springframework.stereotype.Service;

import com.example.demo.model.Books;
import com.example.demo.repository.BooksRepository;

@Service
public class BooksService {
	
	@Resource
	private BooksRepository booksRepository;
	
	
	public Books getById(Integer id) {
		return booksRepository.getOne(id);
	}
	
	public List<Books> findByPage(int num, int size){
		Pageable page= new QPageRequest(num, size);
		Page<Books> findAll = booksRepository.findAll(page);
		return findAll.getContent();
	}
	
	public List<Books> insert(Iterable<Books> arg0) {
		List<Books> saveAll = booksRepository.saveAll(arg0);
		booksRepository.flush();
		return saveAll;
	}

}
